package cn.xyfmzmy.decorator.input;

import java.io.IOException;
import java.io.InputStream;

/**
 * 在BufferedFileInputStream的基础上再装饰一层,记录调用了多少次read方法
 */
public class ReadCountFileInputStream extends InputStream {

    private int readCount = 0;

    private final InputStream inputStream;

    public ReadCountFileInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public int readCount(){
        return this.readCount;
    }

    @Override
    public int read() throws IOException {
        readCount++;
        return inputStream.read();
    }
}
